package com.sinaapp.gavinzhang.ASM;

import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * Created by gavin on 15-8-27.
 */
public class Generator{
    public static void main(String[] args) throws Exception {
        File f = new File("/home/gavin/IdeaProjects/Programming/target/classes/com/sinaapp/gavinzhang/ASM/ForASMTest.class");
        ClassReader cr = new ClassReader(new FileInputStream(f));
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        ClassAdapter classAdapter = new AddSecurityCheckClassAdapter(cw);
        cr.accept(classAdapter, ClassReader.SKIP_DEBUG);
        byte[] data = cw.toByteArray();
        File file = new File("/home/gavin/IdeaProjects/Programming/target/classes/com/sinaapp/gavinzhang/ASM/ForASMTest.class");
        FileOutputStream fout = new FileOutputStream(file);
        fout.write(data);
        fout.close();
    }
}
